package achievement

import (
	"time"

	"gddgame.cc/galaxy/common/dsl/game"
)

const SettingAchievementName = "setting_achievement"

type SettingAchievement struct {
	Id      int               `json:"id" orm:"auto" sql:"INT"`
	Key     string            `json:"key" sql:"VARCHAR"`
	Type    int               `json:"type" sql:"TINYINT"`
	Name    map[string]string `json:"name" sql:"JSON"`
	Desc    map[string]string `json:"desc" sql:"JSON"`
	Icon    string            `json:"icon" sql:"VARCHAR"`
	Score   int               `json:"score" sql:"INT"`
	Factors []game.Factor     `json:"factors" sql:"JSON"`
	Sort    int               `json:"sort" sql:"INT"`

	// 扩展参数：游戏端
	Extend interface{} `json:"extend" sql:"JSON"`
	// 扩展参数：服务端
	Inside interface{} `json:"inside" sql:"JSON"`

	UpdateTime *time.Time `json:"update_time" orm:"updateTime" sql:"DATETIME"`

	goal int32
}

func (achievement *SettingAchievement) GetGoal() int32 {
	if achievement.goal > 0 {
		return achievement.goal
	}
	achievement.goal = int32(0)
	for _, factor := range achievement.Factors {
		achievement.goal += factor.Value
	}
	return achievement.goal
}
